<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <base href="<%=basePath%>">
    <link rel="stylesheet" href="static/component/pear/css/pear.css" />
    <link rel="stylesheet" href="static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="static/css/public.css" media="all">
    <style type="text/css">
        .layui-table-cell {
            height: auto;
            line-height: 28px;
        }
    </style>
</head>
<body>

<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" >
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">分类名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="memberLeveName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="userFormSubmit"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="userTableFilter"></table>

        <script type="text/html" id="userOperate">
            <a class="layui-btn  layui-btn-normal layui-btn-sm "  lay-event="uptate"><i class="layui-icon layui-icon-edit">修改</i></a>
            <a class="layui-btn layui-btn-sm layui-btn-danger   data-count-delete" lay-event="delete"><i class="layui-icon layui-icon-delete">删除</i></a>
        </script>

    </div>

</div>
<script src="static/component/layui/layui.js"></script>
<script src="static/component/pear/pear.js"></script>

<script>
    //引入table
    layui.use(['table','form'],function (){
        var $ = layui.jquery;
        var from = layui.form;
        var table = layui.table;
        var form = layui.form;
        //执行表格的数据填充操作
        table.render({
            //指定渲染的表格
            elem:'#currentTableId',
            //指定获取数据的路径
            url:'memberLeve/selectMemberLeve',
            toolbar:'#toolbarDemo',
            //规定请求方式
            method:'post',
            //开启分页
            page:true,
            check:true,
            //指定每页显示数
            limits:[1,10,15],
            even:true,
            cols:[[
                {type: "checkbox",   align: 'center'},
                {field:'memberLeveId',title:'分类编号',  align: 'center'},
                {field:'memberLeveName',title:'分类名称',  align: 'center'},
                {field:'discount',title:'折扣等级',  align: 'center'},
                {field:'toMoney',title:'开卡金额',  align: 'center'},
                {title: '操作',toolbar:'#userOperate',minWidth:300, align: 'center'},
                /*     {field:'',title:''}*/
            ]],
        })


        //添加删除按钮事件
        table.on('toolbar(userTableFilter)',function (obj){
            if (obj.event==='add') {
                //执行添加
                //执行添加操作
                layer.open({
                    //执行添加会员分类操作
                    title: '添加会员分类信息',
                    type: 2,
                    shade: 0.1,
                    area: ['32%', '70%'],
                    content: 'memberLeve/addMemberLeves'
                })
            }
        });

        //表格事件
        table.on('tool(userTableFilter)',function (obj){
            //判断表格的的操作类型
            if(obj.event==='uptate'){
                //修改客户信息
                layer.open({
                    //执行修改会员分类操作
                    title:'修改会员分类信息',
                    type:2,
                    shade: 0.1,
                    area:['32%','70%'],
                    content: '/memberLeve/updateMemberLeves?memberLeveId='+obj.data.memberLeveId
                })
            }else if(obj.event==='delete'){
                //执行删除
                layer.confirm('真的要删除吗？',function(index){
                    $.post('/memberLeve/deleteMemberLeve',{"memberLeveId":obj.data.memberLeveId},function(res){
                        if (res.success) {
                            layer.msg(res.msg,{
                                icon: 1,
                                time: 1000
                            }, function() {
                                //执行重载
                                table.reload('currentTableId');
                                layer.close(index);
                            });
                        }
                    });

                })

            }

        })

        //from表单提交事件
        form.on('submit(userFormSubmit)',function (data){
            //执行搜索重载
            table.reload('currentTableId',{
                //规定默认第几页
                page:{
                    curr:1
                },
                where:{
                    //添加请求参数
                    memberLeveName:data.field.memberLeveName,
                }
            });
            return false;
        })


    })
</script>
</body>
</html>